<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="schoolId">
        <el-select v-model="queryParams.schoolId" placeholder="请输入所属校区" clearable
                   :style="{width: '100%'}">
          <el-option v-for="(item, index) in schoolIdOptions" :key="index" :label="item.schoolName"
                     :value="item.schoolId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="queryParams.timeNum" placeholder="请输入课时" clearable :style="{width: '100%'}">
          <el-option label="<=5课时" value="5"></el-option>
          <el-option label="<=10课时" value="10" ></el-option>
          <el-option label="<=20课时" value="20" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="queryParams.clsHourNum"
          placeholder="请输入剩余课时"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-s-promotion" size="mini" @click="sendRemind">到期提醒</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="12">
        <div style="margin-bottom: 1.5%">
          <li class="el-icon-user-solid"></li>
          <span style="font-size: 14px"> 需要提醒学员:  </span>
          <span style="padding:1px;background-color: #00afff;font-size: 12px;font-weight: bold;color: white">
            {{'总计'+total+'人'}}
          </span>
        </div>
      </el-col>
    </el-row>
    <el-table stripe border v-loading="loading" :data="remindStuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="学生编号" align="left" prop="studentNumber">
        <template slot-scope="scope">
          <span style="color: #00afff">
            <i class="el-icon-user-solid"></i>
            <span v-text="scope.row.studentNumber"></span>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="学员姓名" align="left" prop="studentName" />
      <el-table-column label="学员电话" align="left" prop="studentPhone" />
      <el-table-column label="所属校区" align="left" prop="schoolName" />
      <el-table-column label="学员课程" align="left" prop="courseName"  />
      <el-table-column label="所属销售" align="left" prop="nickName"/>
      <el-table-column label="剩余课时" align="left" prop="courseHour">
        <template slot-scope="scope">
<!--          <div v-text="scope.row.courseHour"
                :style="scope.row.courseHour >= 20?'{background-color: yellow}':
                        scope.row.courseHour == '10'?'{background-color: orange}':'{background-color: red}'" >
          </div>-->
          <span v-text="scope.row.courseHour+'课时'" style="font-size:5px;background-color:lightskyblue;font-weight:bold;color:white;padding:3px">
          </span>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination :page-size="queryParams.pageSize" layout="total,prev, pager, next" @current-change="currentChange"
                     :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getRemindStu, getListSchool} from "../../../api/student/student";

export default {
  name: "remind",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total:0,
      // 学生表格数据
      remindStuList: [],
      //获取所有校区
      schoolIdOptions: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        clsHourNum: null,
        schoolId: null,
        timeNum: null,
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    this.school();
  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.loading = true;

      getRemindStu(this.queryParams).then((res) => {
        this.remindStuList = res.data
        this.total =res.count
        this.loading = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.studentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /*点击提醒按钮的操作*/
    sendRemind(){
      if(this.ids.length == 0){
        this.msgError("请勾选要提醒的学员!!!")
      }else{
        this.msgSuccess("已发送提醒消息")
      }
    },
    /*获取所有校区*/
    school() {
      getListSchool().then((res) => {
        this.schoolIdOptions = res.data
      })
    },
    /*分页*/
    currentChange(current) {
      this.queryParams.pageNum = current;
      this.getList()
    }
  }
};
</script>
